<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.wy.util.DBUtil" %>
<%@ page import="com.wy.util.MD5Util" %><%--
  Created by IntelliJ IDEA.
  User: 13939
  Date: 2024/11/27
  Time: 22:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //获得登陆表单传递的数据
    String uname = request.getParameter("username");
    String pwd   = request.getParameter("userPwd");
    String password= MD5Util.encrypt(pwd);
    //进行数据库校验
    String sql = "SELECT *, user_pwd AS userPwd FROM news_user WHERE username='" + uname + "' AND user_pwd ='" + password + "'";
    DBUtil dbUtil  = new DBUtil();
    ResultSet rs  = dbUtil.query(sql);
    if(rs.next()){  //有对应用户的记录存在
        //设置session变量
        session.setAttribute("username",rs.getString("username"));
        session.setAttribute("uid",  rs.getInt("uid"));
        response.sendRedirect("../show/show.jsp?");  //跳转到后端首页
    }else {
        out.print("用户名或者密码错误");
    }
%>

